var popupRegStatus = 0;
var popupSigninStatus = 0;
var mouseStatus = 0;

function loadRegPopup(){
	//loads popup only if it is disabled
	if(popupRegStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupReg").fadeIn("slow");
		popupRegStatus = 1;
	}
}
function loadSigninPopup(){
	//loads popup only if it is disabled
	if(popupSigninStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupSignin").fadeIn("slow");
		popupSigninStatus = 1;
	}
}

function disableRegPopup(){
	//disables popup only if it is enabled
	if(popupRegStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupReg").fadeOut("slow");
		popupRegStatus = 0;
	}
}
function disableSigninPopup(){
	//disables popup only if it is enabled
	if(popupSigninStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupSignin").fadeOut("slow");
		popupSigninStatus = 0;
	}
}

function centerRegPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupReg").height();
	var popupWidth = $("#popupReg").width();
	//centering
	$("#popupReg").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


function centerSigninPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupSignin").height();
	var popupWidth = $("#popupSignin").width();
	//centering
	$("#popupSignin").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
function likePopupIn () {
	if (mouseStatus == 1)	
	{
		$("#like-fb").fadeIn("slow");
		$("#like-vk").fadeIn("slow");
		$("#like-gp").fadeIn("slow");
		$("#like-tw").fadeIn("slow");
	}
}
function likePopupOut () {
	
	if (mouseStatus == 0)
	{
		var delay = 500;
		$("#like-fb").fadeOut(delay);
		$("#like-vk").fadeOut(delay);
		$("#like-gp").fadeOut(delay);
		$("#like-tw").fadeOut(delay);
	} else {
		/*$("#likeBtn").clearQueue();*/
	}
}

$(document).ready(function(){

	$("#signup").click(function(){
		//centering with css
		centerRegPopup();
		//load popup
		loadRegPopup();
	});
	$("#signin").click(function(){
		//centering with css
		centerSigninPopup();
		//load popup
		loadSigninPopup();
	});
	
	$("#popupClose").click(function(){
		if (popupRegStatus = 1) {
			disableRegPopup();
		}
		else {
			disableSigninPopup();
		}
	});

	$("#backgroundPopup").click(function(){
		disableRegPopup();
		disableSigninPopup();
	});
	

	$(document).keypress(function(e){
		if(e.keyCode==27 && popupRegStatus==1){
			disableRegPopup();
		}
		if(e.keyCode==27 && popupSigninStatus==1){
			disableSigninPopup();
		}
	});
	
	
	$("#likeBtn").hover(function() {
		mouseStatus = 1;
		setTimeout(likePopupIn, 500);

	}, function() {
		mouseStatus = 0;

		setTimeout(likePopupOut, 250);
	});
	
	$("#like-fb").hover(function() {
		mouseStatus = 1;
	}, function () {
		mouseStatus = 0;
	});
	$("#like-vk").hover(function() {
		mouseStatus = 1;
	}, function () {
		mouseStatus = 0;
	});
	$("#like-gp").hover(function() {
		mouseStatus = 1;
	}, function () {
		mouseStatus = 0;
	});
	$("#like-tw").hover(function() {
		mouseStatus = 1;
	}, function () {
		mouseStatus = 0;
	});
});






